package scau.hotel.hotel_sys.security.domain;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import scau.hotel.hotel_sys.entity.SysUser;

import java.util.Collection;

/**
 * Authentication认证用户类
 */
public class LoginUser implements UserDetails{
    private Long userId;

    private String password;

    private final String username;

    private final Collection<? extends GrantedAuthority> authorities;

    private final boolean accountNonExpired;

    private final boolean accountNonLocked;

    private final boolean credentialsNonExpired;

    private final boolean enabled;

    private SysUser sysUser;

    private Long loginTime;

    private Long expireTime;

    public LoginUser(Long userId, String username, String password, SysUser sysUser, Long loginTime, Long expireTime, Collection<? extends GrantedAuthority> authorities) {
        this(userId, username, password, sysUser, loginTime, expireTime, true, true, true, true, authorities);
    }


    public LoginUser(Long userId, String username, String password, SysUser sysUser, Long loginTime, Long expireTime,  boolean enabled, boolean accountNonExpired,
                       boolean credentialsNonExpired, boolean accountNonLocked,
                       Collection<? extends GrantedAuthority> authorities) {
        this.userId = userId;
        this.username = username;
        this.password = password;
        this.sysUser = sysUser;
        this.loginTime = loginTime;
        this.expireTime = expireTime;
        this.enabled = enabled;
        this.accountNonExpired = accountNonExpired;
        this.credentialsNonExpired = credentialsNonExpired;
        this.accountNonLocked = accountNonLocked;
        this.authorities = authorities;
    }


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return this.accountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return this.accountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return this.credentialsNonExpired;
    }

    @Override
    public boolean isEnabled() {
        return this.enabled;
    }

    public void setSysUser(SysUser sysUser) {
        this.sysUser = sysUser;
    }

    public SysUser getSysUser() {
        return this.sysUser;
    }

    public void setLoginTime(Long loginTime) {
        this.loginTime = loginTime;
    }

    public Long getLoginTime() {
        return this.loginTime;
    }

    public void setExpireTime(Long expireTime) {
        this.expireTime = expireTime;
    }

    public Long getExpireTime() {
        return this.expireTime;
    }

}
